import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

"""
Décomposition du pentoxyde d'azote ; réaction d'ordre 1
N2O5 (g) = 2NO2(g) + 1/2 02(g)
"""
temps = np.array([0,10,20,30,60,90])
concentration = np.array([1.24,0.92,0.68,0.50,0.20,0.08])*0.01

Y = np.log(concentration)

slope, intercept, rvalue, pvalue, stderr = stats.linregress(temps,Y)
print("pente = {}".format(slope))
print("ordonnée à l'origine = {}".format(intercept))
print("R2 = {}".format(rvalue**2))

def predict(x):
    return slope * x + intercept

fitLine = predict(temps)

fig, axes = plt.subplots(2)
fig.suptitle("Décomposition du pentaoxyde d'azote")
axes[0].grid()
axes[0].set(ylim=[0.0,0.015])
axes[0].set(ylabel="Concentration (mol/L)")
axes[1].set(ylabel="log de la concentration")
axes[1].grid()
axes[1].set(xlabel="Temps (min)")
axes[0].scatter(temps,concentration,label="Points expérimentaux")
axes[1].scatter(temps,Y,label="Points expérimentaux")
axes[1].plot(temps,fitLine,color='r',label="Droite de régression linéaire\n y = {}x + {}".format(round(slope,4),round(intercept,4)))
axes[0].legend()
axes[1].legend()
plt.show()

